package com.hackerrank.challenges.ajourney;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution {
	private static int indexOf(int v, List<Integer> list) {
		int l = 0, u = list.size() - 1;
		while(l <= u) {
			int m = (l + u) / 2;
			if(v > list.get(m))
				l = m + 1;
			else if(v < list.get(m))
				u = m - 1;
			else
				return m;
		}
		return -1;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int N = in.nextInt(), K = in.nextInt(), v = 1, mk = (int)Math.pow(10, K), i = -1, RV;
			List<Integer> lk = new ArrayList<Integer>();
			while(i < 0 && lk.size() < N) {
				lk.add(v);
				v = (v * 2) % mk;
				i = indexOf(v, lk);
			}
			if(i < 0)
				RV = lk.get(lk.size() - 1);
			else {
				int R = lk.size() - i, NR = (N - i) % R;
				if(NR == 0) {
					if(N >= i)
						RV = lk.get(i + R - 1);
					else
						RV = lk.get(i - 1);
				} else
					RV = lk.get(i + NR - 1);
			}
			double e = (N - 1) * Math.log10(2);
			e = e - (long)e + K - 1;
			System.out.println((int)Math.pow(10, e) + RV);
		}
	}
}
